﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;
using SelfService.Model;


namespace SelfService.ViewModel.SysClientLogVMs
{
    public partial class SysClientLogListVm : BasePagedListVM<SysClientLogView, SysClientLogSearcher>
    {

        protected override IEnumerable<IGridColumn<SysClientLogView>> InitGridHeader()
        {
            return new List<GridColumn<SysClientLogView>>{
                this.MakeGridHeader(x => x.客户端),
                this.MakeGridHeader(x => x.Info),
                this.MakeGridHeader(x => x.Module),
                this.MakeGridHeader(x => x.Level),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysClientLogView> GetSearchQuery()
        {
            var query = DC.Set<SysClientLog>()
                .CheckEqual(Searcher.ClientId, x=>x.ClientId)
                .CheckContain(Searcher.Info, x=>x.Info)
                .CheckContain(Searcher.Module, x=>x.Module)
                .CheckContain(Searcher.Level, x => x.Level)
                .WhereIf(Searcher.StartTime != null && Searcher.EndTime != null, x => x.CreateTime >= Searcher.StartTime && x.CreateTime <= Searcher.EndTime)
                .Select(x => new SysClientLogView
                {
				    ID = x.ID,
                    客户端 = x.Client.Name,
                    Info = x.Info,
                    Module = x.Module,
                    Level = x.Level,
                    CreateTime = x.CreateTime,
                })
                .OrderByDescending(x => x.CreateTime);
            return query;
        }

    }

    public class SysClientLogView : SysClientLog{
        [Display(Name = "名称")]
        public String 客户端 { get; set; }

    }
}
